import store from "@/store"
import { getComponentListByTypes } from "./utils"
import { analysisComponentTypes } from "./const"
import { dataSignalQuery } from "@/api/multidimensionalAnalysis"
import { getAllAnalysisComponentByEditType,filterFieldTypes, getFieldListByComponentList } from "./analysisData"
/**
 * 获取下拉框的数据,即下拉框筛选字段的options
 * @param { Component[] } analysisComponentList
 */
export async function getTableList(analysisComponentList){
  getSelectFilterFieldListOptions(analysisComponentList)
  .then(tableList => {
    store.commit("lowCode/setSelectFilterFieldList", tableList)
  })

}


/**
 * 获取业务组件和字段的列表options
 * @param { Component[] } analysisComponentList
 * @returns { Promise<GroupOption[]> }
 */
export async function getSelectFilterFieldListOptions(analysisComponentList){
  const tableList = await getFieldListByComponentList(analysisComponentList, true, ["INT", "STRING"])
  return tableList
}

/**
 * 查询某个字段的可选值列表, 即默认值的options
 * @param {*} type
 * @param {*} columnName
 * @param {*} params
 */
export async function getTableOption(type, columnName, params){
  params.columnName = columnName
  return new Promise((resolve, reject)=> {
    const commonCallback = (data, callback) => {
      if(data.errorCode === 0){
        callback(data.data)
      }
      else {
        reject()
      }
    }
    // switch (type) {
    //   case 3:
        const success = data => {
          console.log(data)
          const list = data.map((item, index) => {
            console.log(item, index)
            return {
              label: item[columnName],
              value: item[columnName]
            }
          })
          resolve(list)
        }
        dataSignalQuery(params)
        .then(data => commonCallback(data, success))
    // }
  })


}
